﻿using AutoPex.Core;
using Microsoft.Cci;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.IO;

namespace AutoPex
{
	class Program
	{
		static void Main(string[] args)
		{
			var methodsToAnalyze = new AssemblyDiffer().GetMethodsToAnalyze(
				new FileInfo(args[0]), new FileInfo(args[1]));
			
			var methodNamesToAnalyze = new List<string>();
			
			foreach(var methodToAnalyze in methodsToAnalyze)
			{
				Console.Out.WriteLine(methodToAnalyze.ToString());
				methodNamesToAnalyze.Add(methodToAnalyze.Name.Value);
			}

			var startInformation = new ProcessStartInfo("pex");
			startInformation.CreateNoWindow = false;
			startInformation.Arguments = args[1] + " /nor /erm:wizard /mmf:M:" +
				string.Join(";", methodNamesToAnalyze.ToArray());
			startInformation.RedirectStandardOutput = true;
			startInformation.UseShellExecute = false;

			var pex = Process.Start(startInformation);
			pex.WaitForExit();

			var pexOutput = pex.StandardOutput.ReadToEnd();
			
			Console.Out.WriteLine(pexOutput);
		}
	}
}
